package com.stormrage.shiro.filter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.apache.shiro.web.util.WebUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author www.stormragetech.com
 * @date 2016年3月12日
 * @version 1.0.0
 */
public class LoginFormAuthenticationFilter extends FormAuthenticationFilter {

	private static final Logger logger = LoggerFactory.getLogger(LoginFormAuthenticationFilter.class);

	@Override
	protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request,
			ServletResponse response) throws Exception {

		logger.debug(" request 为 " + WebUtils.getSavedRequest(request));
		// String url = WebUtils.getSavedRequest(request).getRequestUrl();
		// logger.debug(" 上一个请求地址为 " + url);
		WebUtils.getAndClearSavedRequest(request);
		WebUtils.redirectToSavedRequest(request, response, "/");
		return false;

	}

}
